home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / callbutn / btrv.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  15.6 KB  |  542 lines

  1. VERSION 2.00
  2. Begin Form Btrv 
  3.    Caption         =   "Sample program using CallBtrv()"
  4.    ClientHeight    =   5160
  5.    ClientLeft      =   225
  6.    ClientTop       =   495
  7.    ClientWidth     =   7380
  8.    Height          =   5565
  9.    Left            =   165
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5160
  13.    ScaleWidth      =   7380
  14.    Top             =   150
  15.    Width           =   7500
  16.    Begin CommandButton Command18 
  17.       Caption         =   "Exit"
  18.       Height          =   375
  19.       Left            =   6000
  20.       TabIndex        =   33
  21.       Top             =   4560
  22.       Width           =   855
  23.    End
  24.    Begin CommandButton Command17 
  25.       Caption         =   "Get >"
  26.       Height          =   375
  27.       Left            =   4320
  28.       TabIndex        =   28
  29.       Top             =   4560
  30.       Width           =   855
  31.    End
  32.    Begin CommandButton Command16 
  33.       Caption         =   "Get <"
  34.       Height          =   375
  35.       Left            =   4320
  36.       TabIndex        =   27
  37.       Top             =   4080
  38.       Width           =   855
  39.    End
  40.    Begin TextBox INo 
  41.       Height          =   285
  42.       Left            =   3240
  43.       TabIndex        =   40
  44.       Top             =   3960
  45.       Width           =   615
  46.    End
  47.    Begin TextBox FNo 
  48.       Height          =   285
  49.       Left            =   1320
  50.       TabIndex        =   38
  51.       Top             =   3960
  52.       Width           =   855
  53.    End
  54.    Begin CommandButton Command4 
  55.       Caption         =   "End"
  56.       Height          =   375
  57.       Left            =   6000
  58.       TabIndex        =   3
  59.       Top             =   3600
  60.       Width           =   855
  61.    End
  62.    Begin CommandButton Command15 
  63.       Caption         =   "Get >="
  64.       Height          =   375
  65.       Left            =   4320
  66.       TabIndex        =   26
  67.       Top             =   3600
  68.       Width           =   855
  69.    End
  70.    Begin TextBox Text10 
  71.       Height          =   285
  72.       Left            =   1320
  73.       TabIndex        =   36
  74.       Top             =   3600
  75.       Width           =   2775
  76.    End
  77.    Begin TextBox Keylength 
  78.       Height          =   285
  79.       Left            =   1320
  80.       TabIndex        =   32
  81.       Top             =   3240
  82.       Width           =   1695
  83.    End
  84.    Begin CommandButton Command3 
  85.       Caption         =   "Close"
  86.       Height          =   375
  87.       Left            =   6000
  88.       TabIndex        =   2
  89.       Top             =   3120
  90.       Width           =   855
  91.    End
  92.    Begin CommandButton Command14 
  93.       Caption         =   "Get <="
  94.       Height          =   375
  95.       Left            =   4320
  96.       TabIndex        =   25
  97.       Top             =   3120
  98.       Width           =   855
  99.    End
  100.    Begin TextBox Key 
  101.       Height          =   285
  102.       Left            =   1320
  103.       TabIndex        =   30
  104.       Top             =   2880
  105.       Width           =   2775
  106.    End
  107.    Begin CommandButton Command9 
  108.       Caption         =   "Delete"
  109.       Height          =   375
  110.       Left            =   6000
  111.       TabIndex        =   19
  112.       Top             =   2640
  113.       Width           =   855
  114.    End
  115.    Begin CommandButton Command13 
  116.       Caption         =   "Get ="
  117.       Height          =   375
  118.       Left            =   4320
  119.       TabIndex        =   24
  120.       Top             =   2640
  121.       Width           =   855
  122.    End
  123.    Begin TextBox Text9 
  124.       Height          =   285
  125.       Left            =   360
  126.       TabIndex        =   17
  127.       Top             =   2280
  128.       Width           =   3735
  129.    End
  130.    Begin CommandButton Command8 
  131.       Caption         =   "Insert"
  132.       Height          =   375
  133.       Left            =   6000
  134.       TabIndex        =   18
  135.       Top             =   2160
  136.       Width           =   855
  137.    End
  138.    Begin CommandButton Command12 
  139.       Caption         =   "GetPrev"
  140.       Height          =   375
  141.       Left            =   4320
  142.       TabIndex        =   23
  143.       Top             =   2160
  144.       Width           =   855
  145.    End
  146.    Begin TextBox Text8 
  147.       Height          =   285
  148.       Left            =   360
  149.       TabIndex        =   16
  150.       Top             =   2040
  151.       Width           =   3735
  152.    End
  153.    Begin TextBox Text7 
  154.       Height          =   285
  155.       Left            =   360
  156.       TabIndex        =   15
  157.       Top             =   1800
  158.       Width           =   3735
  159.    End
  160.    Begin CommandButton Command7 
  161.       Caption         =   "Update"
  162.       Height          =   375
  163.       Left            =   6000
  164.       TabIndex        =   8
  165.       Top             =   1680
  166.       Width           =   855
  167.    End
  168.    Begin CommandButton Command6 
  169.       Caption         =   "GetNext"
  170.       Height          =   375
  171.       Left            =   4320
  172.       TabIndex        =   7
  173.       Top             =   1680
  174.       Width           =   855
  175.    End
  176.    Begin TextBox Text6 
  177.       Height          =   285
  178.       Left            =   360
  179.       TabIndex        =   14
  180.       Top             =   1560
  181.       Width           =   3735
  182.    End
  183.    Begin TextBox Text5 
  184.       Height          =   285
  185.       Left            =   360
  186.       TabIndex        =   13
  187.       Top             =   1320
  188.       Width           =   3735
  189.    End
  190.    Begin CommandButton Command19 
  191.       Caption         =   "Create"
  192.       Height          =   375
  193.       Left            =   6000
  194.       TabIndex        =   34
  195.       Top             =   1200
  196.       Width           =   855
  197.    End
  198.    Begin CommandButton Command11 
  199.       Caption         =   "Get Last"
  200.       Height          =   375
  201.       Left            =   4320
  202.       TabIndex        =   22
  203.       Top             =   1200
  204.       Width           =   855
  205.    End
  206.    Begin TextBox Text4 
  207.       Height          =   285
  208.       Left            =   360
  209.       TabIndex        =   12
  210.       Top             =   1080
  211.       Width           =   3735
  212.    End
  213.    Begin TextBox Text3 
  214.       Height          =   285
  215.       Left            =   360
  216.       TabIndex        =   11
  217.       Top             =   840
  218.       Width           =   3735
  219.    End
  220.    Begin CommandButton Command2 
  221.       Caption         =   "Open"
  222.       Height          =   375
  223.       Left            =   6000
  224.       TabIndex        =   1
  225.       Top             =   720
  226.       Width           =   855
  227.    End
  228.    Begin CommandButton Command5 
  229.       Caption         =   "Get First"
  230.       Height          =   375
  231.       Left            =   4320
  232.       TabIndex        =   6
  233.       Top             =   720
  234.       Width           =   855
  235.    End
  236.    Begin TextBox Text2 
  237.       Height          =   285
  238.       Left            =   360
  239.       TabIndex        =   10
  240.       Top             =   600
  241.       Width           =   3735
  242.    End
  243.    Begin TextBox Text1 
  244.       Height          =   285
  245.       Left            =   360
  246.       TabIndex        =   9
  247.       Top             =   360
  248.       Width           =   3735
  249.    End
  250.    Begin CommandButton Command1 
  251.       Caption         =   "Init"
  252.       Height          =   375
  253.       Left            =   6000
  254.       TabIndex        =   0
  255.       Top             =   240
  256.       Width           =   855
  257.    End
  258.    Begin CommandButton Command10 
  259.       Caption         =   "Use"
  260.       Height          =   375
  261.       Left            =   4320
  262.       TabIndex        =   20
  263.       Top             =   240
  264.       Width           =   855
  265.    End
  266.    Begin Label Label2 
  267.       Height          =   255
  268.       Left            =   1320
  269.       TabIndex        =   5
  270.       Top             =   4440
  271.       Width           =   615
  272.    End
  273.    Begin Label Label1 
  274.       Caption         =   "RetCode"
  275.       Height          =   255
  276.       Left            =   360
  277.       TabIndex        =   4
  278.       Top             =   4440
  279.       Width           =   735
  280.    End
  281.    Begin Label Label8 
  282.       Caption         =   "Key #"
  283.       Height          =   255
  284.       Left            =   2400
  285.       TabIndex        =   39
  286.       Top             =   3960
  287.       Width           =   735
  288.    End
  289.    Begin Label Label7 
  290.       Caption         =   "File #"
  291.       Height          =   255
  292.       Left            =   360
  293.       TabIndex        =   37
  294.       Top             =   3960
  295.       Width           =   855
  296.    End
  297.    Begin Label Label6 
  298.       Caption         =   "Filename"
  299.       Height          =   255
  300.       Left            =   360
  301.       TabIndex        =   35
  302.       Top             =   3600
  303.       Width           =   855
  304.    End
  305.    Begin Label Label5 
  306.       Caption         =   "Keylen"
  307.       Height          =   255
  308.       Left            =   360
  309.       TabIndex        =   31
  310.       Top             =   3240
  311.       Width           =   615
  312.    End
  313.    Begin Label Label4 
  314.       Caption         =   "Keyval"
  315.       Height          =   255
  316.       Left            =   360
  317.       TabIndex        =   29
  318.       Top             =   2880
  319.       Width           =   615
  320.    End
  321.    Begin Label Label3 
  322.       Height          =   375
  323.       Left            =   5280
  324.       TabIndex        =   21
  325.       Top             =   240
  326.       Width           =   615
  327.    End
  328. Sub Command1_Click ()
  329.     Dim Switches As String
  330.     Rem set Btrieve switches
  331.     Switches = "/m:48 /p:2048 /b:16 /f:20 /l:20 /n:12"
  332.     Rem initialize Btrieve
  333.     BStatus = WBtrvInit(Switches)
  334.     Rem show Btrieve return code
  335.     Label2.Caption = Str$(BStatus)
  336. End Sub
  337. Sub Command10_Click ()
  338.     Rem this returns the number of records in the file
  339.     CallBtrv B_USE, FileNo, 0
  340.     Label2.Caption = Str$(BStatus)
  341.     Label3.Caption = KeyVal
  342. End Sub
  343. Sub Command11_Click ()
  344.     CallBtrv GET_LAST, FileNo, KeyNo
  345.     ShowAcct
  346. End Sub
  347. Sub Command12_Click ()
  348.     CallBtrv GET_PREV, FileNo, KeyNo
  349.     ShowAcct
  350. End Sub
  351. Sub Command13_Click ()
  352.     KeyVal = Key.Text
  353.     CallBtrv GET_EQ, FileNo, KeyNo
  354.     ShowAcct
  355. End Sub
  356. Sub Command14_Click ()
  357.     KeyVal = Key.Text
  358.     CallBtrv GET_LE, FileNo, KeyNo
  359.     ShowAcct
  360. End Sub
  361. Sub Command15_Click ()
  362.     KeyVal = Key.Text
  363.     CallBtrv GET_GE, FileNo, KeyNo
  364.     ShowAcct
  365. End Sub
  366. Sub Command16_Click ()
  367.     KeyVal = Key.Text
  368.     CallBtrv GET_LT, FileNo, KeyNo
  369.     ShowAcct
  370. End Sub
  371. Sub Command17_Click ()
  372.     KeyVal = Key.Text
  373.     CallBtrv GET_GT, FileNo, KeyNo
  374.     ShowAcct
  375. End Sub
  376. Sub Command18_Click ()
  377.     Unload Btrv
  378.     End
  379. End Sub
  380. Sub Command19_Click ()
  381.     Rem disable this command so we don't delete the sample file
  382.     Rem given with program
  383.     Rem this sample code is given to show how to set up a buffer to enable
  384.     Rem a program to create a file
  385.     Exit Sub
  386.     Rem dimension Specs for key characteristics for 6 segments
  387.     Dim Specs As KEY_6SEG
  388.     Rem the file number
  389.     FileNo = Val(FNo.Text)
  390.     Rem set KeyNo to 0 to create a file over an existing file
  391.     Rem set KeyNo to -1 if you do not want Btrieve to create a new file
  392.     Rem over an existing file - Btrieve will return an error code.
  393.     KeyNo = Val(INo.Text)
  394.     Rem assign file characteristics
  395.     Specs.RecLen = GlAcctLen        ' length of record
  396.     Specs.PgSize = 1024             ' page size
  397.     Specs.NoOfIndex = 3             ' number of keys
  398.     Specs.NotUsed = 0&
  399.     Specs.FileFlags = H0%           ' file specifications
  400.     Specs.ResWrd = 0
  401.     Specs.Alloc = 0                 ' space to preallocate
  402.     Rem key specifications
  403.     Specs.KeyPos1 = 1               ' position of first segment
  404.     Specs.KeyLen1 = 20              ' length of first segment
  405.     Specs.KeyFlags1 = KF_STRING + KF_MODIFIABLE     ' key characteristics
  406.     Specs.NotUsed1 = 0&
  407.     Specs.Ext_Nul1 = 0
  408.     Specs.ResWrd1 = 0&
  409.     Specs.KeyPos2 = 1               ' position of second segment ...
  410.     Specs.KeyLen2 = 8
  411.     Specs.KeyFlags2 = KF_STRING + KF_MODIFIABLE + KF_SEGMENT
  412.     Specs.NotUsed2 = 0&
  413.     Specs.Ext_Nul2 = 0
  414.     Specs.ResWrd2 = 0&
  415.     Specs.KeyPos3 = 13
  416.     Specs.KeyLen3 = 8
  417.     Specs.KeyFlags3 = KF_STRING + KF_MODIFIABLE + KF_SEGMENT
  418.     Specs.NotUsed3 = 0&
  419.     Specs.Ext_Nul3 = 0
  420.     Specs.ResWrd3 = 0&
  421.     Specs.KeyPos4 = 9
  422.     Specs.KeyLen4 = 3
  423.     Specs.KeyFlags4 = KF_STRING + KF_MODIFIABLE
  424.     Specs.NotUsed4 = 0&
  425.     Specs.Ext_Nul4 = 0
  426.     Specs.ResWrd4 = 0&
  427.     Specs.KeyPos5 = 1
  428.     Specs.KeyLen5 = 8
  429.     Specs.KeyFlags5 = KF_STRING + KF_DUPLICATE + KF_MODIFIABLE + KF_SEGMENT
  430.     Specs.NotUsed5 = 0&
  431.     Specs.Ext_Nul5 = 0
  432.     Specs.ResWrd5 = 0&
  433.     Specs.KeyPos6 = 65
  434.     Specs.KeyLen6 = 12
  435.     Specs.KeyFlags6 = KF_STRING + KF_DUPLICATE + KF_MODIFIABLE
  436.     Specs.NotUsed6 = 0&
  437.     Specs.Ext_Nul6 = 0
  438.     Specs.ResWrd6 = 0&
  439.     LSet BtrvBuf = Specs                ' assign file characteristics to Btrieve buffer
  440.     CallBtrv B_CREATE, FileNo, KeyNo    ' create the file
  441.     Label2.Caption = Str$(BStatus)
  442. End Sub
  443. Sub Command2_Click ()
  444.     Rem open a Btrieve file
  445.     Rem the key number contains how the file is opened
  446.     Rem OM_NORNAL = read/write using pre-imaging
  447.     Rem OM_ACCELERATED = accelerated access
  448.     Rem OM_READONLY = read only
  449.     Rem OM_VERIFY = verifies data is correct on all writes
  450.     Rem OM_EXCLUSIVE = exclusive mode
  451.     CallBtrv B_OPEN, FileNo, OM_NORMAL
  452.     Label2.Caption = Str$(BStatus)
  453. End Sub
  454. Sub Command3_Click ()
  455.     CallBtrv B_CLOSE, FileNo, KeyNo
  456.     Label2.Caption = Str$(BStatus)
  457. End Sub
  458. Sub Command4_Click ()
  459.     Rem stop Btrieve
  460.     Rem usually you would put this in a Form_Unload event
  461.     Rem be sure to close all files first
  462.     BStatus = WBtrvStop()
  463.     Label2.Caption = Str$(BStatus)
  464. End Sub
  465. Sub Command5_Click ()
  466.     CallBtrv GET_FIRST, FileNo, KeyNo
  467.     ShowAcct
  468. End Sub
  469. Sub Command6_Click ()
  470.     CallBtrv GET_NEXT, FileNo, KeyNo
  471.     Label2.Caption = Str$(BStatus)
  472.     ShowAcct
  473. End Sub
  474. Sub Command7_Click ()
  475.     ChartRec.GlId = Text1.Text
  476.     ChartRec.GlAcct = Text2.Text
  477.     ChartRec.GlName = Text3.Text
  478.     ChartRec.GlType = Text4.Text
  479.     ChartRec.GlParen = Val(Text5.Text)
  480.     ChartRec.GlMaster = Val(Text6.Text)
  481.     ChartRec.GlBalance = Val(Text7.Text)
  482.     ChartRec.GlSort = Text8.Text
  483.     ChartRec.GlNoOfHist = Val(Text9.Text)
  484.     CallBtrv B_UPDATE, FileNo, KeyNo
  485.     UpdateVars
  486. End Sub
  487. Sub Command8_Click ()
  488.     ChartRec.GlId = Text1.Text
  489.     ChartRec.GlAcct = Text2.Text
  490.     ChartRec.GlName = Text3.Text
  491.     ChartRec.GlType = Text4.Text
  492.     ChartRec.GlParen = Val(Text5.Text)
  493.     ChartRec.GlMaster = Val(Text6.Text)
  494.     ChartRec.GlBalance = Val(Text7.Text)
  495.     ChartRec.GlSort = Text8.Text
  496.     ChartRec.GlNoOfHist = Val(Text9.Text)
  497.     CallBtrv B_INSERT, FileNo, KeyNo
  498.     UpdateVars
  499. End Sub
  500. Sub Command9_Click ()
  501.     CallBtrv B_DELETE, FileNo, 0
  502.     UpdateVars
  503. End Sub
  504. Sub FNo_LostFocus ()
  505.     FileNo = Val(FNo.Text)
  506. End Sub
  507. Sub Form_Load ()
  508.     ' change the path to your directory
  509.     Path = "m:\vb\btrv\"
  510.     FileName(0) = "GLACCT.BTR"
  511.     Rem integer containing the length of each key
  512.     Rem in the form KeyLen(FileNo,KeyNo)
  513.     KeyLen(0, 0) = 20
  514.     KeyLen(0, 1) = 19
  515.     KeyLen(0, 2) = 20
  516.     INo.Text = "0"          ' default key number
  517.     FNo.Text = "0"          ' default file number
  518.     FileNo = 0
  519.     KeyNo = 0
  520.     Text10.Text = Path + FileName(FileNo)
  521. End Sub
  522. Sub INo_LostFocus ()
  523.     KeyNo = Val(INo.Text)
  524. End Sub
  525. Sub ShowAcct ()
  526.     Text1.Text = ChartRec.GlId
  527.     Text2.Text = ChartRec.GlAcct
  528.     Text3.Text = ChartRec.GlName
  529.     Text4.Text = ChartRec.GlType
  530.     Text5.Text = Str$(ChartRec.GlParen)
  531.     Text6.Text = Str$(ChartRec.GlMaster)
  532.     Text7.Text = Format$(ChartRec.GlBalance, "##,###,##0.00")
  533.     Text8.Text = ChartRec.GlSort
  534.     Text9.Text = Str$(ChartRec.GlNoOfHist)
  535.     UpdateVars
  536. End Sub
  537. Sub UpdateVars ()
  538.     Label2.Caption = Str$(BStatus)
  539.     Key.Text = KeyVal
  540.     KeyLength.Text = Str$(Len(KeyVal))
  541. End Sub
  542.